<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <style type="text/css">
            div{
                float:left;
                border:10px solid red;
            }
        </style>
    </head>
    <body>
        <div>
            <img src="image/pangzi.png" alt="" id="oImg" />
        </div>
    </body>
    <script type="text/javascript">
        var oBox = document.getElementsByTagName("div")[0];
        var oImg = document.getElementById("oImg");


        // alert(oBox.offsetWidth);

        //当图片加载完后执行函数
        oImg.onload = function(){

            alert(oBox.offsetWidth);
        }

    </script>
</html>